package com.zw.admin.server.dao;

import com.zw.admin.server.commom.TkMapper;
import com.zw.admin.server.model.Device;
import com.zw.admin.server.model.SpaceDevice;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface SpaceDeviceDao extends TkMapper<SpaceDevice> {

    @Select("select device.* " +
            "from bsn_device as device " +
            "right  join bsn_space_device as spaceDevice on device.id = spaceDevice.device_id " +
            "where spaceDevice.space_id =  ${params.spaceId} " +
            "limit #{offset}, #{limit}")
    List<Device> listAll(@Param("params") Map<String, Object> params, Integer offset, Integer limit);

    @Select("select count(1) " +
            "from bsn_device as device " +
            "right  join bsn_space_device as spaceDevice on device.id = spaceDevice.device_id " +
            "where spaceDevice.space_id =  ${params.spaceId} ")
    int countSpaceDevice(@Param("params") Map<String, Object> params);


    @Delete("delete from bsn_space_device where space_id = #{space_id}")
    int deleteSpaceDeviceBySpaceId(Long space_id);


    @Delete("delete from bsn_space_device where device_id = #{device_id}")
    int deleteBySpaceDeviceId(Long device_id);

    @Delete("delete from bsn_space_device where device_id = #{deviceId} ")
    int delBySpaceIdAndDeviceId(String spaceId, String deviceId);

    @Insert("INSERT INTO bsn_space_device (space_id, device_id ) VALUES (#{spaceId},#{deviceId});")
    int addBySpaceIdAndDeviceId(String spaceId, String deviceId);

    @Select("select device_id from bsn_space_device where space_id = #{spaceId}")
    List<String> getSpaceDeviceIds(Long spaceId);
}
